package cn.lingyangwl.agile.infra.misc.service.impl;

import cn.lingyangwl.agile.infra.misc.assembly.*;
import cn.lingyangwl.agile.infra.misc.service.*;
import cn.lingyangwl.agile.infra.module.misc.*;
import cn.lingyangwl.framework.ip2region.handler.*;
import cn.lingyangwl.framework.ip2region.model.*;
import cn.lingyangwl.framework.tool.core.exception.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author shenguangyang
 */
@Slf4j
@Service
public class InfraCommonServiceImpl implements InfraCommonService {
    @Resource
    private InfraCommonAssembly commonAssembly;
    @Resource
    private Ip2RegionHandler ip2RegionHandler;

    @Override
    public Ip2RegionDto ip2Region(String ip) {
        try {
            AddressInfo address = ip2RegionHandler.getAddress(ip);
            return commonAssembly.toDto(address);
        } catch (Exception e) {
            log.error("error: ", e);
            return null;
        }
    }
}
